﻿using FastEndpoints;
using FluentValidation;

namespace Ke.Bee.Transcription.Models;

/// <summary>
/// 语音转文字请求参数
/// </summary>
public class TranscriptionRequest(string connectionId, string taskId, string fileName, string filePath)
{
    public string ConnectionId { get; set; } = connectionId;
    public string TaskId { get; set; } = taskId;
    public string FileName { get; set; } = fileName;
    public string FilePath { get; set; } = filePath;
    public string Language { get; set; } = "zh-CN";
    public string Model { get; set; } = "base";
    public int SliceDuration { get; set; } = 10;
    public int SilenceThreshold { get; set; } = 500;
}

public class TranscriptionRequestValidator : Validator<TranscriptionRequest>
{
    public TranscriptionRequestValidator()
    {
        RuleFor(x => x.Language)
            .NotEmpty().WithMessage("语言参数不能为空")
            .Matches(@"^[a-zA-Z\-]+$").WithMessage("语言格式不正确");

        RuleFor(x => x.Model)
            .NotEmpty().WithMessage("模型参数不能为空")
            .Matches(@"^[a-zA-Z0-9\-]+$").WithMessage("模型格式不正确");

        RuleFor(x => x.SliceDuration)
            .GreaterThan(0).WithMessage("切片时长必须大于0")
            .LessThanOrEqualTo(60).WithMessage("切片时长不能超过60秒");

        RuleFor(x => x.SilenceThreshold)
            .GreaterThan(0).WithMessage("静默阈值必须大于0")
            .LessThanOrEqualTo(5000).WithMessage("静默阈值不能超过5000");
    }
}